package com.zh.harmony.ormlitesample.dao;

import com.zh.harmony.ormlitesample.entity.ArticleEntity;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * 文章表Dao
 */
public class ArticleDao extends BaseDao<ArticleEntity, Long> {
    public ArticleDao(Class<ArticleEntity> entityClazz) {
        super(entityClazz);
    }

    public ArticleDao() {
        super(ArticleEntity.class);
    }

    /**
     * 根据用户Id，查询该用户下的所有文章
     */
    public List<ArticleEntity> queryByUserId(long userId) {
        List<ArticleEntity> result = null;
        try {
            result = mDao.queryBuilder()
                    .where()
                    .eq("user_id", userId)
                    .query();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        if (result == null) {
            result = new ArrayList<>();
        }
        return result;
    }
}